package com.yfp.client.controller;

import com.yfp.client.annotation.AnonymousAccess;
import com.yfp.client.domain.*;
import com.yfp.client.domain.vo.MiniBannerVO;
import com.yfp.client.service.*;
import com.yfp.client.util.Response;
import com.yfp.client.domain.*;
import com.yfp.client.service.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Description: 小程序banner
 *
 * @CreateDate: 2024/7/22 11:38
 * @UpdateUser:
 * @UpdateDate: 2024/7/22 11:38
 * @UpdateRemark: 暂无修改
 * @Version: 1.0
 */
@RestController
@RequestMapping("/client/miniBanner")
@Tag(name = "小程序banner")
public class MiniBannerController {
    @Autowired
    private MiniBannerService miniBannerService;
    @Autowired
    private ClientActivityService clientActivityService;
    @Autowired
    private MarCouponPackService marCouponPackService;
    @Resource
    private ActivitySignInsService activitySignInsService;
    @Resource
    private LotteryRecordsService lotteryRecordsService;

    @Operation(summary = "banner列表")
    @GetMapping("")
    @AnonymousAccess
    public Response<MiniBannerVO> findListSortAndCreateTime(String cityName) {
        MiniBannerVO miniBannerVO = new MiniBannerVO();
        List<MiniBanner> miniBanners = miniBannerService.findListSortAndCreateTime(cityName);
        for (MiniBanner miniBanner : miniBanners) {
            if (null != miniBanner.getMarketingId()){
                Marketing marketing = clientActivityService.findMarketingById(miniBanner.getMarketingId());
                miniBanner.setMarketingType(0);
                switch (marketing.getType()){
                    case 1:
                        MarCoupon marCoupon = clientActivityService.findMarCouponById(marketing.getMarCouponId());
                        miniBanner.setMarketingStatus(marCoupon.getStatus());
                        miniBanner.setMarketingType(1);
                        break;
                    case 2:
                        MarActivity marActivity = clientActivityService.findMarActivityById(marketing.getMarActivityId());
                        miniBanner.setMarketingStatus(marActivity.getStatus());
                        miniBanner.setMarketingType(2);
                        break;
                    case 3:
                        MarCouponPack marCouponPack = marCouponPackService.findById(marketing.getMarCouponPackId());
                        miniBanner.setMarketingStatus(marCouponPack.getStatus());
                        miniBanner.setMarketingType(3);
                        break;
                    case 4:
                        LotteryRecords lotteryRecords = lotteryRecordsService.getById(marketing.getLotteryRecordsId());
                        miniBanner.setMarketingStatus(lotteryRecords.getStatus());
                        miniBanner.setMarketingType(4);
                        break;
                    case 5:
                        ActivitySignIns activitySignIns = activitySignInsService.getById(marketing.getActivitySignInsId());
                        miniBanner.setMarketingStatus(activitySignIns.getStatus());
                        miniBanner.setMarketingType(5);
                        break;
                }
            }
        }
        Map<Integer, List<MiniBanner>> miniBannerMap = miniBanners.stream().collect(Collectors.groupingBy(MiniBanner::getPosition));
        miniBannerVO.setHostBanners(miniBannerMap.get(1));
        miniBannerVO.setHostBottomBanners(miniBannerMap.get(2));
        miniBannerVO.setPopupBanners(miniBannerMap.get(3));
        miniBannerVO.setEatBanners(miniBannerMap.get(4));
        miniBannerVO.setMallBanners(miniBannerMap.get(5));
        return Response.success(miniBannerVO);
    }
}